Skip to content

refactor(engine): reduce complexity of collect_allowed_tools in src/engine.rs#1454

Merged
jamesadevine merged 2 commits into
mainfrom
refactor/reduce-complexity-collect-allowed-tools-a958d533e77a3bf6
Jul 15, 2026
Merged

refactor(engine): reduce complexity of collect_allowed_tools in src/engine.rs#1454
jamesadevine merged 2 commits into
mainfrom
refactor/reduce-complexity-collect-allowed-tools-a958d533e77a3bf6

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

What was complex

collect_allowed_tools in src/engine.rs was a ~90-line monolithic function with three distinct concerns packed together, resulting in three nested loops and two inline match arms (estimated cognitive complexity ~20):

  1. Collect extension tools — a doubly-nested loop over extension_declarations → copilot_allow_tools with a dedup check
  2. Collect MCP server tools — a loop over sorted MCP configs with an inline match to decide whether a config has a backing MCPG server
  3. Build bash command list — another doubly-nested loop plus a match arm on front_matter.tools.bash

What changed

Extracted four named helpers, leaving collect_allowed_tools as a 25-line coordinator:

New function Responsibility
collect_extension_tools Dedup-collect tool names from all extension declarations
mcp_server_has_backing_server Pure predicate: does this McpConfig have a container or URL?
add_mcp_server_tools Append sorted MCP server names to the tool list (skipping duplicates and non-backed servers)
build_bash_command_list Merge front-matter bash commands with extension-declared bash commands

No public API signatures changed. Behaviour is identical.

Complexity

  • Before: ~20 (estimated; below Clippy's default threshold of 25)
  • After: ~5 (coordinator only; Clippy clean at all tested thresholds)

Verification

  • cargo test — all tests pass
  • cargo clippy --all-targets --all-features — zero warnings

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • spsprodeus21.vssps.visualstudio.com

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "spsprodeus21.vssps.visualstudio.com"

See Network Configuration for more information.

Generated by Cyclomatic Complexity Reducer · 92.8 AIC · ⌖ 12.4 AIC · ⊞ 7.2K ·

Extract collect_extension_tools, mcp_server_has_backing_server,
add_mcp_server_tools, and build_bash_command_list from the monolithic
collect_allowed_tools function.

Before: single ~90-line function with three nested loops and two
in-line match arms (estimated cognitive complexity ~20).
After: collect_allowed_tools is a 25-line coordinator; each concern
is named and independently testable.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jamesadevine
jamesadevine marked this pull request as ready for review July 13, 2026 11:03
@jamesadevine

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

…exity-collect-allowed-tools-a958d533e77a3bf6

# Conflicts:
#	src/engine.rs

Co-authored-by: jamesadevine <4742697+jamesadevine@users.noreply.github.com>

Copilot AI commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in e480c75. The only conflict was in src/engine.rs where main had introduced collect_extension_allowed_tools (with a push_unique_tool helper) doing the same job as our collect_extension_tools. The resolution keeps our add_mcp_server_tools, mcp_server_has_backing_server, and build_bash_command_list helpers and the refactored collect_allowed_tools coordinator, while switching to main's naming (collect_extension_allowed_tools) and removing the duplicate. All tests pass.

Copilot AI requested a review from jamesadevine July 13, 2026 11:10
@jamesadevine
jamesadevine merged commit 15686f6 into main Jul 15, 2026
9 checks passed
@jamesadevine
jamesadevine deleted the refactor/reduce-complexity-collect-allowed-tools-a958d533e77a3bf6 branch July 15, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants